package com.bosssoft.user.permission.center.serve.util;

import com.bosssoft.user.permission.center.serve.dao.entity.Role;
import com.bosssoft.user.permission.center.serve.pojo.query.UserEntity;
import com.bosssoft.user.permission.center.serve.pojo.vo.UserVo;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class UserTypeUtil {
    public static UserVo userTypeUtil1(UserEntity userEntity) {
        UserVo userVo = new UserVo();
        userVo.setId(userEntity.getId().toString());
        userVo.setUsername(userEntity.getUsername());
        userVo.setPassword(userEntity.getPassword());
        userVo.setUserStatus(userEntity.getUserStatus());
        userVo.setUserCharacter(userEntity.getUserCharacter());
        userVo.setCompany(userEntity.getCompany());
        userVo.setPosition(userEntity.getPosition());
        userVo.setGender(userEntity.getGender());
        userVo.setTelephone(userEntity.getTelephone());
        userVo.setUserId(userEntity.getUserId());
        userVo.setBirthday(userEntity.getBirthday());

        userVo.setDepartment(userEntity.getDepartment());
        userVo.setTenantId(userEntity.getTenantId());
        userVo.setCompanyId(userEntity.getCompanyId());
        return userVo;
    }
    public static String userTypeUtil2(List<Role> role) {
        StringBuilder sb = new StringBuilder();
        if(role.size()>0){
            sb.append(role.get(0).getName());
            for(int i = 1;i<role.size();i++){
                sb.append(",").append(role.get(i).getName());
            }
        }else{
            return sb.toString();
        }
        return sb.toString();
    }

    public static HashMap<String,Object> userTypeUtil3(UserEntity userEntity) {
        HashMap<String,Object> hashmap = new HashMap<String,Object>();
        hashmap.put("id",userEntity.getId());
        hashmap.put("code",userEntity.getUserId());
        hashmap.put("password",userEntity.getPassword());
        hashmap.put("name",userEntity.getUsername());
        if(userEntity.getGender().equals("男")){
            hashmap.put("sex",0);
        }else{
            hashmap.put("sex",1);
        }
        hashmap.put("tenant_id",userEntity.getTenantId());
        hashmap.put("company_id",userEntity.getCompanyId());
        hashmap.put("created_by","1");
        hashmap.put("created_time",new Date());
        hashmap.put("updated_by","1");
        hashmap.put("updated_time",new Date());
        hashmap.put("status",userStatusUtil(userEntity.getUserStatus()));
        hashmap.put("version","1");
        return hashmap;
    }
    public static Integer userStatusUtil(String status) {
        if(status.equals("published")){
            return 1;
        }else if(status.equals("draft")){
            return 2;
        }else{
            return 3;
        }
    }
}
